package szcg.framework.library.config.db;


import com.alibaba.druid.pool.DruidDataSource;
import szcg.framework.library.config.constant.DBConfig;
import szcg.framework.library.utils.HardwareUtils;

/**
 * hm
 * 主数据源
 */
public class CustomDruidDataSource extends DruidDataSource {

    public CustomDruidDataSource() {
        String url = DBConfig.ds1.get("url");
        String Username = DBConfig.ds1.get("Username");
        String Password = DBConfig.ds1.get("Password");
        String DriverClassName = DBConfig.ds1.get("DriverClassName");
        setUrl(url);
        setUsername(Username);
        setPassword(Password);
        setDriverClassName(DriverClassName);
        int cores = HardwareUtils.getCores();
        //初始化配置
        setInitialSize(cores == 0 ? 1 : cores * 2);
        setMaxActive(cores == 0 ? 1 : cores * 10);
        setMinIdle(cores == 0 ? 1 : cores * 2);
        setFailFast(true);
    }
}
